home *** CD-ROM | disk | FTP | other *** search
- /* scanf.c --- p 462 */
- #include <stdio.h>
- #include <math.h>
- main()
- {
- int num_months;
- double interest_rate, principal, final_amount;
- /* Ask user to enter all necessary amounts */
- printf("Enter amount of principal, annual interest rate:");
- scanf(" %lf %lf", &principal, &interest_rate);
- printf("Enter number of months before deposit matures:");
- scanf(" %d", &num_months);
- /* Compute amount at maturity and print value */
- final_amount = principal * pow((1.0 + interest_rate/12.0/100.0),
- (double)num_months);
- printf("$%.2f @%.2f%% annual rate yields $%.2f "
- "after %d months\n", principal, interest_rate,
- final_amount, num_months);
- }